/*
 * @Descripttion:
 * @Author: YuZhenJing
 * @Date: 2020-01-01 11:53:29
 * @LastEditors: YuZhenJing
 * @LastEditTime: 2020-05-18 16:43:34
 */
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack')
const apiIp = '129.211.82.243'
module.exports = {
  entry: {
    app: './src/index.js',
  },
  devServer: {
    port: 8600,
    proxy: {
      '/asmcore': {
        target: 'http://' + apiIp + ':9891',
        changeOrigin: true,
        pathRewrite: {
          '^/asmcore': '/asmcore',
        },
      },
      '/asmbody': {
        target: 'http://' + apiIp + ':9892',
        changeOrigin: true,
        pathRewrite: {
          '^/asmbody': '/asmbody',
        },
      },
      '/example': {
        target: 'http://' + apiIp + ':9893',
        changeOrigin: true,
        pathRewrite: {
          '^/example': '/example',
        },
      },
    },
    historyApiFallback: { index: '/' },
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
    disableHostCheck: true,
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: process.env.npm_package_productName,
      description: process.env.npm_package_description,
      template: './index.html',
    }),
    new webpack.DefinePlugin({
      'process.env': { mode: '"dev"', myIp: '"localhost"' },
    }),
  ],
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /(node_modules)/,
        include: [path.resolve(__dirname, '../src')],
        use: {
          loader: 'babel-loader',
        },
      },
    ],
  },
}
